﻿using System;
using System.Windows.Data;
using System.Windows.Media;

using Finance.Entites;

namespace Finance.UI.Utils
{
    public class CashAmountColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            //if (typeof(double).IsAssignableFrom(value.GetType()))
            //{
            //    Color foreColor = Colors.Black;
            //    var amount = System.Convert.ToInt32((double)value);
            //    if (amount >= 0) { foreColor = Colors.Green; }
            //    else { foreColor = Colors.Red; }
            //    return new SolidColorBrush(foreColor);
            //}
            //throw new ArgumentException("Invalid data type, type of double is required.");

            if (typeof(Charge).IsAssignableFrom(value.GetType()))
            {
                Color foreColor =
                    value is IncomeCharge ? Colors.Green :
                    value is PayoutCharge ? Colors.Red :
                    Colors.Black;
                return new SolidColorBrush(foreColor);
            }
            throw new ArgumentException("Invalid data type, type of Charge is required.");
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException("No need to convert back.");
        }
    }
}
